package com.code.leetcode.before50;

/**
 * @author codeDorado
 * @version 1.0
 * @date 2020/7/20 10:51
 */
public class The28 {
    public int strStr(String haystack, String needle) {
        int hlen = haystack.length();
        int nlen = needle.length();

        if (nlen > hlen) return -1;
        if (nlen == 0) return 0;
        for (int i = 0; i < hlen - nlen + 1; i++) {
            if (haystack.charAt(i) == needle.charAt(0)) {
                if (haystack.substring(i, i + nlen).equals(needle))
                    return i;
            }
        }
        return -1;
    }

}
